package com.tkjt.pms.calc.formula.common;

import java.util.HashMap;
import java.util.Map;

public class FormulaRules {
	
	private Map<String, FormulaRule> classifiedRules = new HashMap<String, FormulaRule>();

	public FormulaRule searchRule(String whichData, String indexValueCode, String indexDepart) {
		String key = indexValueCode + "@" + whichData + "@" + indexDepart;
		Object rule = classifiedRules.get(key);
		if (null == rule) {
			key = indexValueCode + "@" + whichData + "@";
			rule = classifiedRules.get(key);
		}
		if (null == rule) {
			key = indexValueCode + "@@" + indexDepart;
			rule = classifiedRules.get(key);
		}
		if (null == rule) {
			key = indexValueCode + "@@";
			rule = classifiedRules.get(key);
		}
		return (FormulaRule) rule;
	}
	
	public void addFormula(String ruleKey, FormulaRule formulaRule) {
		classifiedRules.put(ruleKey, formulaRule);
	}
	
	public boolean isEmpty() {
		return classifiedRules.isEmpty();
	}

}
